package com.dxx.D201910312055;


import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.provider.Settings;
import android.view.View;
import android.widget.Switch;
import android.widget.Toast;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.dxx.D201910312055.auto.Auto_Brush_the_treasure;
import com.dxx.D201910312055.auto.Auto_Lightning_box;
import com.dxx.D201910312055.dxx.AutoService;
import com.dxx.D201910312055.dxx.ScreenActivity;

public class MainActivity extends ScreenActivity {
//public class MainActivity extends Activity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.auto_home);
//        LayoutInflater inflate = LayoutInflater.from(this);
////        view = inflate.inflate(R.layout.auto_home, null);
//        View view = inflate.inflate(R.layout.login, null);
//        setContentView(view);
        floatingWindow();

    }

    @Override
    protected void onStart() {


        super.onStart();


    }


    @Override
    protected void onDestroy() {
        super.onDestroy();

    }


    //    刷宝
    public void Auto_Brush_the_treasure_loginSwitch(View view) {

        //必须是Switch才能转换，不然异常
        boolean isChecked = ((Switch) view).isChecked();
//        exampleClient.send("");
////////////////////////////////////////////////////////////////

        if (isChecked) {
            //选中时 do some thing
            AutoService.mService.startAuto("com.dxx.D201910312055.auto.Auto_Brush_the_treasure", 0);


            if (Auto_Brush_the_treasure.ClassNameData[0].equals("")) {

                String s = LoginActivity.exampleClient.getMessage("com.jm.video");

                if (!s.equals("")) {

                    JSONArray arr = JSON.parseArray(s);
                    Auto_Brush_the_treasure.ClassNameData[0] = arr.getString(0);
                    Auto_Brush_the_treasure.ClassNameData[1] = arr.getString(1);
                    Auto_Brush_the_treasure.ClassNameData[2] = arr.getString(2);
                } else {
                    Toast.makeText(this, "服务器异常，脚本开启失败", Toast.LENGTH_SHORT).show();
                    AutoService.mService.onStop();
                }

            }


        } else {
            //非选中时 do some thing
            AutoService.mService.startAuto("", 0);
        }

    }


    //闪电盒子
    public void Auto_Lightning_box_Switch(View view) {

        //必须是Switch才能转换，不然异常
        boolean isChecked = ((Switch) view).isChecked();
//        exampleClient.send("");
////////////////////////////////////////////////////////////////
//
        if (isChecked) {
//            //选中时 do some thing
            AutoService.mService.startAuto("com.dxx.D201910312055.auto.Auto_Lightning_box", 0);


            if (Auto_Lightning_box.ClassNameData[0].equals("")) {

                String s = LoginActivity.exampleClient.getMessage("c.l.a");

                if (!s.equals("")) {

                    JSONArray arr = JSON.parseArray(s);
                    Auto_Lightning_box.ClassNameData[0] = arr.getString(0);
                    Auto_Lightning_box.ClassNameData[1] = arr.getString(1);
//                    Auto_Lightning_box.ClassNameData[2] = arr.getString(2);
                } else {
                    Toast.makeText(this, "服务器异常，脚本开启失败", Toast.LENGTH_SHORT).show();
                    AutoService.mService.onStop();
                }

            }


        } else {
//            //非选中时 do some thing
            AutoService.mService.startAuto("", 0);
        }

    }

    public void ExitLogin_auto_home_button(View view) {
        Intent intent = new Intent(MainActivity.this, LoginActivity.class);
        startActivity(intent);
        LoginActivity.exampleClient.close();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
//            wmParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
        } else {

            try {
                this.startActivity(new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS));
            } catch (Exception e) {
                this.startActivity(new Intent(Settings.ACTION_SETTINGS));
//                e.printStackTrace();
            }

//            wmParams.type = WindowManager.LayoutParams.TYPE_PHONE;
        }
    }


}
